home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000174_icon-group-sender_Mon Dec 18 09:27:24 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
4KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id eBIGRKk01190
for icon-group-addresses; Mon, 18 Dec 2000 09:27:20 -0700 (MST)
Message-Id: <200012181627.eBIGRKk01190@baskerville.CS.Arizona.EDU>
Date: Sat, 16 Dec 2000 08:26:58 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Subject: Re: Stepping
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 3005
John Sampson wrote:
>
> It would be useful to be able to step through an Icon program or set
> break-points in some simple way. I would have thought
>
> dummy := read()
> ...
I though others might like to see how this idea can be easily extended
to support a simple debugging controller. The following procedure
pauses the program and allows the user to type some simple debugging
commands. Typing EOF or "q" terminates the program, "c" or "n" continues
program execution, "l" shows local (and global) variables, "g" shows
only global variables, and "a" shows a stack trace of all variables.
Finally "h" prints a simple help message.
The programmer can pass in a special prompt or let it default to
a standard prompt. (Passing in a prompt makes it easier to
identify where in the program you've paused...).
Of course, you could extend this to add any number of commands, and
even write a version where the programmer could optionally pass in
addition commands to allow when the procedure is called.
I think I've seen better versions of similar ideas posted before - a
*long* time ago. If you have one, how about reposting it?
(As an aside, this could become a class in Unicon and do some *really*
impressive debugging...)
---- snip "debug.icn" ---
#
# Simple debugger controller. Responds to user-issued debug commands.
#
# Still requires user to press Enter after each command, though EOF
# terminates program immediately.
#
procedure debugCtl(prompt)
# Loop until user quits program or asks to continue
#
repeat {
writes((\prompt | "Debug")," (h for help): ")
(map(read()) | "q") ? {
if ="q" then stop("Program terminated by user.")
else if ="h" then { # help message
write("\nCommands are:\n")
write("\tquit (or EOF) -- terminate program now")
write("\thelp -- display help")
write("\tcontinue -- continue program execution")
write("\tnext -- same as continue")
write("\tlocals -- display local variables")
write("\tglobals -- display global variables")
write("\tall -- display all variables in stack trace")
write("\nOnly first character of command is needed.\n")
}
else if =("c"|"n") then return # continue execution
else if ="l" then { # display local (and global) variables
display(2) # to bad it also shows local vars for debugCtl!
}
else if ="g" then { # display only global variables
display(0)
}
else if ="a" then { # display full stack dump
display()
}
} # end of string scanning
} # end of repeat loop
end
--- end snip "debug.icn" ----
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu